package de.tabuma.pm.gadget.controller;

import de.tabuma.lib.tabumacontroller;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import de.tabuma.pm.*;
import de.tabuma.pm.gadget.entity.*;
import de.tabuma.pm.gadget.logik.*;
import com.google.appengine.api.users.*;

/**
 *
 * @author alefen
 */
public class remove extends tabumacontroller {

    public remove(String servlet, Hashtable hashtable) {
        super(servlet, hashtable);
    }

    @Override
    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
        String gadgetActionId = request.getParameter(constants.gadgetActionId);
        int gadgetActionIdInt = Integer.valueOf(gadgetActionId).intValue();
        if(gadgetActionIdInt==constants.GADGET_ACTION_REMOVE) {
            String gadgetId = request.getParameter(constants.gadgetId);
            int gadgetIdInt = Integer.valueOf(gadgetId).intValue();
            Gadget gadget = GadgetFacade.get(gadgetIdInt);

            UserService userService = UserServiceFactory.getUserService();
            User user = userService.getCurrentUser();

            GadgetFacade.remove(gadget, gadgetId);
            list list = new list(this.getServlet(), this.getParameter());
            list.navigate(context, request, response, out);
        }
    }
}
